import java.util.ArrayList;
import java.util.Collections;



public class Ex1_4 {
	
	/*
	 * Main method
	 */
	public static void main(String[] args) {
		
		try {
			// input parameters
			int k = 9;
			int l = 500;
			int t = 3;				
						
			String genome = KmerCounter.readFile("C:\\Users\\josemfer\\Downloads\\E-coli.txt").trim();		
			//String genome = "CGGACTCGACAGATGTGAAGAACGACAATGTGAAGACTCGACACGACAGAGTGAAGAGAAGAGGAAACATTGTAA";
			
			// internal vars
			ArrayList<String> result = new ArrayList<String>();
			String kmer;
			int kcount;
			
			// visit all genome
			for (int i=0;i < genome.length() - k; i++) {
				// reset kmer counter
				kcount = 0;
				// get potential kmer
				kmer = genome.substring(i,i+k);
				// read from i-th position to end of genome, searching k-mers
				for (int j=i;  j < genome.length() - k ;j++) {
					if (result.contains(kmer)) {
						break;
					}
					// matching kmers
					//System.out.println("i:" + i + "  j:" + j);
					if (genome.substring(j,j+k).equals(kmer)        ) {
						kcount++;
					}
					
					if (kcount >= t &&  (j-i > l) ) {						
						if (!result.contains(kmer)) {
							result.add(kmer);
							//System.out.print(kmer + " ");
						}						
						break;
					}
					
				} // for j						
			} // all genome
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}			
	} // main
	
	
	
	
	
	
}
